package com.ruoyi.airspaceFlight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.airspaceFlight.domain.FlyApply;
import com.ruoyi.airspaceFlight.service.IFlyApplyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 飞行计划申请Controller
 *
 * @author zc
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/flyapply")
public class FlyApplyController extends BaseController {
    @Autowired
    private IFlyApplyService flyApplyService;

    /**
     * 查询飞行计划申请列表
     */
//    @RequiresPermissions("airspaceFlight:flyapply:list")
    @PostMapping ("/list")
    public TableDataInfo list(@RequestBody FlyApply flyApply) {
        startPage();
        List<FlyApply> list = flyApplyService.selectFlyApplyList(flyApply);
        return getDataTable(list);
    }


    /**
     * 导出飞行计划申请列表
     */
//    @RequiresPermissions("airspaceFlight:flyapply:export")
    @Log(title = "飞行计划申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlyApply flyApply) {
        List<FlyApply> list = flyApplyService.selectFlyApplyList(flyApply);
        ExcelUtil<FlyApply> util = new ExcelUtil<FlyApply>(FlyApply.class);
        util.exportExcel(response, list, "飞行计划申请数据");
    }

    /**
     * 获取飞行计划申请详细信息
     */
//    @RequiresPermissions("airspaceFlight:flyapply:query")
    @GetMapping(value = "/{flyApplyId}")
    public AjaxResult getInfo(@PathVariable("flyApplyId") String flyApplyId) {
        return AjaxResult.success(flyApplyService.selectFlyApplyByFlyApplyId(flyApplyId));
    }

    /**
     * 新增飞行计划申请
     */
//    @RequiresPermissions("airspaceFlight:flyapply:add")
    @Log(title = "飞行计划申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlyApply flyApply) {
        return toAjax(flyApplyService.insertFlyApply(flyApply));
    }

    /**
     * 修改飞行计划申请
     */
//    @RequiresPermissions("airspaceFlight:flyapply:edit")
    @Log(title = "飞行计划申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlyApply flyApply) {
        return toAjax(flyApplyService.updateFlyApply(flyApply));
    }

    /**
     * 删除飞行计划申请
     */
//    @RequiresPermissions("airspaceFlight:flyapply:remove")
    @Log(title = "飞行计划申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{flyApplyIds}")
    public AjaxResult remove(@PathVariable String[] flyApplyIds) {
        return toAjax(flyApplyService.deleteFlyApplyByFlyApplyIds(flyApplyIds));
    }
}
